package com.cskaoyan.shopping.controller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.mall.constant.ShoppingRetCode;
import com.cskaoyan.shopping.dto.AllProductCateResponse;
import com.cskaoyan.shopping.dto.HomePageResponse;
import com.cskaoyan.shopping.dto.NavListResponse;
import com.cskaoyan.shopping.service.IContentService;
import com.cskaoyan.shopping.service.IHomeService;
import com.cskaoyan.shopping.service.IProductCateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @auther: wubang
 * @description:
 * @date: 2022-07-09 15:03
 */
@RestController
public class ShoppingController {
    @Autowired
    IHomeService iHomeService;
    @Autowired
    IContentService iContentService;
    @Autowired
    IProductCateService iProductCateService;

    /**
     * @author wubang
     * @description 主页显示
     * @date 2022/7/9 16:20
     */
    @GetMapping("/shopping/homepage")
    public ResponseData getHomepage(){
        HomePageResponse response = iHomeService.homepage();
        if (ShoppingRetCode.SUCCESS.getCode().equals(response.getCode())){
            //执行成功
            return new ResponseUtil().setData(response.getPanelContentItemDtos());
        }
        //执行失败
        return new ResponseUtil().setErrorMsg(response.getMsg());
    }

    /**
     * @author wubang
     * @description 导航栏显示
     * @date 2022/7/9 16:20
     */
    @GetMapping("/shopping/navigation")
    public ResponseData getNavigation(){
        NavListResponse response = iContentService.queryNavList();
        if (ShoppingRetCode.SUCCESS.getCode().equals(response.getCode())){
            //执行成功
            return new ResponseUtil().setData(response.getPannelContentDtos());
        }
        //执行失败
        return new ResponseUtil().setErrorMsg(response.getMsg());
    }

    /**
     * @author wubang
     * @description 列举所有商品种类
     * @date 2022/7/9 16:21
     */
    @GetMapping("/shopping/categories")
    public ResponseData getCategories(){
        AllProductCateResponse response = iProductCateService.getAllProductCate();
        if (ShoppingRetCode.SUCCESS.getCode().equals(response.getCode())){
            //执行成功
            return new ResponseUtil().setData(response.getProductCateDtoList());
        }
        //执行失败
        return new ResponseUtil().setErrorMsg(response.getMsg());
    }

}
